package com.hl.card.config;
import com.hl.card.common.util.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


@Component
@Order(1)
public class StockConfig implements CommandLineRunner{
	@Autowired
	private StockService stockService;
    public void init()
    {
        String redisKey = "redis_key:stock:rob";
        long stock = stockService.initStock(redisKey, 0, () -> initStock());
        System.out.println("初始化库存数量"+stock);
    }
	@Override
	public void run(String... args) throws Exception {
		init();
	}

    /**
     * 获取初始的库存
     *
     * @return
     */
    private int initStock() {
        // TODO 这里做一些初始化库存的操作
        return 1000;
    }
}
